package com.grace.controller;

import com.grace.common.JsonData;
import com.grace.dto.AclModuleLevelDto;
import com.grace.dto.DeptLevelDto;
import com.grace.model.SysAclModule;
import com.grace.param.AclModuleParam;
import com.grace.service.SysAclModuleService;
import com.grace.service.SysTreeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 权限管理控制层
 */
@Controller
@RequestMapping("/sys/aclModule")
@Slf4j
public class SysAclModuleController {

    @Autowired
    private SysAclModuleService sysAclModuleService;

    @Autowired
    private SysTreeService sysTreeService;

    /**
     * page页面
     */
    @RequestMapping("/acl.page")
    @ResponseBody
    public ModelAndView page() {
        return new ModelAndView("acl");
    }

    /**
     * 新增操作
     */
    @RequestMapping("/save.json")
    @ResponseBody
    public JsonData save(AclModuleParam param) {
        sysAclModuleService.save(param);
        return JsonData.success();
    }

    /**
     * 更新操作
     */
    @RequestMapping("/update.json")
    @ResponseBody
    public JsonData update(AclModuleParam param) {
        sysAclModuleService.update(param);
        return JsonData.success();
    }

    /**
     * 遍历树
     */
    @RequestMapping("/tree.json")
    @ResponseBody
    public JsonData treeData() {
        List<AclModuleLevelDto> dtoList = sysTreeService.aclModuleTree();
        return JsonData.success(dtoList);
    }

    /**
     * 删除权限模块
     */
    @RequestMapping("/delete.json")
    @ResponseBody
    public JsonData delete(@RequestParam("id") int id) {
        sysAclModuleService.delete(id);
        return JsonData.success();
    }

}
